package com.slmxz.tms.document.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.slmxz.tms.common.annotation.Log;
import com.slmxz.tms.common.enums.LogModuleEnum;
import com.slmxz.tms.common.model.Query;
import com.slmxz.tms.common.result.PageResult;
import com.slmxz.tms.common.result.Result;
import com.slmxz.tms.common.support.Condition;
import com.slmxz.tms.document.model.vo.BusinessVO;
import com.slmxz.tms.document.service.BusinessService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 业务类型前端控制层
 * @author sunyao
 * @Date 2024-11-15
 */
@Tag(name = "业务类型接口")
@RestController
@RequestMapping("/document/businesss")
@RequiredArgsConstructor
public class BusinessController  {

    private final BusinessService businessService;

    @Operation(summary = "业务类型分页列表")
    @GetMapping("/page")
    public PageResult<BusinessVO> getBusinessPage(BusinessVO business, Query query) {
        IPage<BusinessVO> result = this.businessService.selectBusinessPage(Condition.getPage(query),business);
        return PageResult.success(result);
    }

    @Operation(summary = "新增业务类型")
    @PostMapping
    @Log(value="新增业务数据",module = LogModuleEnum.BUSINESS)
    @PreAuthorize("@ss.hasPerm('document:business:add')")
    public Result<Void> saveBusiness(@RequestBody @Valid BusinessVO business) {
        boolean result = this.businessService.saveBusiness(business);
        return Result.result(result);
    }

    @Operation(summary = "获取业务类型表单数据")
    @GetMapping("/detail/{id}")
    @PreAuthorize("@ss.hasPerm('document:business:edit')")
    public Result<?> selectBusinessDetail( @Parameter(description = "业务类型ID") @PathVariable Long id) {
        BusinessVO business = this.businessService.selectBusinessDetail(id);
        return Result.success(business);
    }

    @Operation(summary = "修改业务类型")
    @PostMapping(value = "/updateBusiness")
    @PreAuthorize("@ss.hasPerm('document:business:edit')")
    public Result<Void> updateBusiness(@RequestBody @Validated BusinessVO business) {
        boolean result = this.businessService.updateBusiness(business);
        return Result.result(result);
    }

    @Operation(summary = "删除业务类型")
    @DeleteMapping("/{ids}")
    @Log(value = "删除业务数据",module = LogModuleEnum.BUSINESS)
    @PreAuthorize("@ss.hasPerm('document:business:delete')")
    public Result<Void> deleteBusinesss(@Parameter(description = "业务类型ID，多个以英文逗号(,)分割") @PathVariable String ids) {
        boolean result = this.businessService.deleteBusinesss(ids);
        return Result.result(result);
    }


    @Operation(summary = "激活或者注销业务数据")
    @PostMapping("/activeOrLogout")
    @Log(value = "激活或者注销业务数据",module = LogModuleEnum.BUSINESS)
    @PreAuthorize("@ss.hasPerm('document:business:delete')")
    public Result<Void> activeOrLogout(@RequestBody BusinessVO business) {
        boolean result = this.businessService.activeOrLogout(business);
        return Result.result(result);
    }
}
